#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


void *pthread1(void *arg);
void *pthread2(void *arg);

int main()
{
	pthread_t thread_id1,thread_id2;
	void *thread_result1, *thread_result2;
	int res;
	
	res = pthread_create(&thread_id1,NULL,pthread1,NULL);
	if(res){
		perror("pthread1 is not created ...\n");
		exit(EXIT_FAILURE);
	}

	res = pthread_create(&thread_id2,NULL,pthread2,NULL);
	if(res){
		perror("pthread2 is not created ...\n");
		exit(EXIT_FAILURE);
	}

	res = pthread_join(thread_id1,&thread_result1);
	if(res){
		perror("pthread1 join failed ...\n");
		exit(EXIT_FAILURE);
	}

	res = pthread_join(thread_id2,&thread_result2);
	if(res){
		perror("pthread2 join failed ...\n");
		exit(EXIT_FAILURE);
	}
	
	printf("the pthread1 return %s\n",(char *)thread_result1);
	printf("the pthread2 return %s\n",(char *)thread_result2);
	return 0;
}


void *pthread1(void *arg)
{
	int i;
	for(i=0;i<10;i++){
		printf("hello this is pthread1 --> %d\n",i);
		sleep(1);
	}
	pthread_exit("pthread1 finished ...\n");	
}

void *pthread2(void *arg)
{
	int i;
	for(i=0;i<10;i++){
		printf("hello this is pthread2 --> %d\n",i);	
		sleep(1);
	}
	pthread_exit("pthread2 finished ...\n");
}
